package org.example.iris.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.example.iris.entity.Enroll;
import org.springframework.stereotype.Repository;

@Repository
@Mapper
public interface EnrollMapper {

    /**
     * 插入一条 enroll 记录
     * @param enroll Enroll 对象
     * @return 插入的记录数
     */
    @Insert("INSERT INTO enroll (company_id, admin_id, status) " +
            "VALUES (#{companyId}, null, 'pending')")
    int insertEnrollRecord(Enroll enroll);

    /**
     * 根据 enrollId 查询对应的公司ID
     * @param enrollId enrollId
     * @return 对应的 companyId
     */
    @Select("SELECT company_id FROM enroll WHERE enroll_id = #{enrollId}")
    Integer getCompanyIdByEnrollId(Integer enrollId);

    //管理员审核后更新enroll记录
    @Update("UPDATE enroll SET admin_id = #{adminId},status=#{status} WHERE company_id = #{companyId}")
    int updateEnrollRecord(int adminId, int companyId,String status);

}
